package cn.edu.jsu.official.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;

/**
 * @author Mo
 * @createTime 2022/4/27 22:15
 * @description
 */
@Slf4j
public class UploadPathUtil {
    public static ArrayList<String> getSystemRoot() {

        /**
         * 存放doc,docx,pdf 文件上传路径
         * 存放images 文件上传路径
         */
        ArrayList<String> list = new ArrayList<>(2);


        String osName = System.getProperty("os.name");

        // windows目录
        String windowsUpload = System.getProperty("user.dir")+"\\src\\main\\resources\\upload\\";

        // linux目录
        String linuxUpload = System.getProperty("user.dir")+"/upload/";
        log.info("当前系统为: "+osName);

        if (osName.toLowerCase().startsWith("linux")) {
            list.add(linuxUpload+"document/");
            list.add(linuxUpload+"docResources/");
            return list;
        } else if (osName.toLowerCase().startsWith("windows")) {
            list.add(windowsUpload+"document\\");
            list.add(windowsUpload+"docResources\\");
            return list;
        } else {
            throw new RuntimeException("错误目录");
        }
    }

    public static void main(String[] args) {
        ArrayList<String> systemRoot = UploadPathUtil.getSystemRoot();
        System.out.println(systemRoot.get(0) + systemRoot.get(1));
    }
}

